﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Reflection;
using System.Diagnostics;
using Microsoft.SharePoint.Administration;

namespace CKS.Sandbox.Admin.Layouts.CKS.Sandbox.Admin
{
    public partial class CustomiseErrorMessages : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSave.Click += new EventHandler(btnSave_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);

            if (!Page.IsPostBack)
            {
                txtAssemblyUrl.Text = Utility.CustomErrorMessages.GetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedAssembly);
                txtFileTypeUrl.Text = Utility.CustomErrorMessages.GetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedFileTypes);
                txtSolutionUrl.Text = Utility.CustomErrorMessages.GetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedSolution);
            }
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            if (Utility.CustomErrorMessages.GetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedAssembly) != txtAssemblyUrl.Text.Trim())
            {
                Utility.CustomErrorMessages.SetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedAssembly, txtAssemblyUrl.Text.Trim());
            }

            if (Utility.CustomErrorMessages.GetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedFileTypes) != txtFileTypeUrl.Text.Trim())
            {
                Utility.CustomErrorMessages.SetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedFileTypes, txtFileTypeUrl.Text.Trim());
            }

            if (Utility.CustomErrorMessages.GetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedSolution) != txtSolutionUrl.Text.Trim())
            {
                Utility.CustomErrorMessages.SetErrorPageUrl(Utility.CustomErrorMessages.ErrorPages.UnauthorisedSolution, txtSolutionUrl.Text.Trim());
            }

            Response.Redirect("/");
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("/");
        }
    }
}
